<script>
import { checkLogin } from '@/utils/auth'
import { getUserProfile } from '@/api/user'

export default {
  onLaunch: function() {
    console.log('App Launch')
    
    // 检查登录状态
    this.checkLoginStatus()
    
    // 初始化uView配置
    this.initUViewConfig()
  },
  onShow: function() {
    console.log('App Show')
  },
  onHide: function() {
    console.log('App Hide')
  },
  methods: {
    // 检查登录状态
    async checkLoginStatus() {
      try {
        const isLogin = checkLogin()
        if (isLogin) {
          // 获取用户信息
          const userInfo = await getUserProfile()
          // Vue2中可以直接使用this.$u.vuex
          if (this.$u && this.$u.vuex) {
            this.$u.vuex('userInfo', userInfo.data)
          }
        }
      } catch (error) {
        console.error('检查登录状态失败:', error)
      }
    },
    
    // 初始化uView配置
    initUViewConfig() {
      // 设置uView主题色
      try {
        if (this.$u) {
          this.$u.config.unit = 'rpx'
          this.$u.config.type = ['primary', 'success', 'info', 'warning', 'error']
          console.log('✅ uView config initialized')
        }
      } catch (error) {
        console.warn('⚠️ uView config initialization failed:', error)
      }
    }
  }
}
</script>

<style lang="scss">
/* 引入uView基础样式 */
@import "uview-ui/index.scss";

/* 全局样式重置 */
page {
  background-color: #f8f9fa;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', SimSun, sans-serif;
}

/* 自定义全局样式 */
.container {
  padding: 20rpx;
}

.page-padding {
  padding: 0 30rpx;
}

.safe-area-inset-bottom {
  padding-bottom: env(safe-area-inset-bottom);
}

/* 通用按钮样式 */
.btn-primary {
  background: linear-gradient(45deg, #5daf34, #3cc51f);
  color: white;
  border-radius: 50rpx;
  padding: 24rpx 60rpx;
  font-size: 32rpx;
  font-weight: 500;
  border: none;
}

.btn-secondary {
  background: white;
  color: #3cc51f;
  border: 2rpx solid #3cc51f;
  border-radius: 50rpx;
  padding: 24rpx 60rpx;
  font-size: 32rpx;
  font-weight: 500;
}

/* 卡片样式 */
.card {
  background: white;
  border-radius: 20rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
  margin-bottom: 20rpx;
}

/* 头像样式 */
.avatar {
  border-radius: 50%;
  border: 4rpx solid #f0f0f0;
}

/* 状态标签 */
.status-tag {
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  font-size: 24rpx;
  color: white;
  
  &.success {
    background: #19be6b;
  }
  
  &.warning {
    background: #ff9900;
  }
  
  &.error {
    background: #fa3534;
  }
  
  &.info {
    background: #2979ff;
  }
}

/* 文本省略 */
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-ellipsis-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 居中布局 */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-start {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

/* uView组件样式覆盖 */
.u-search {
  background-color: #f5f5f5 !important;
}

.u-icon {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.u-badge {
  z-index: 999 !important;
}

.u-avatar {
  display: inline-block !important;
}

.u-rate {
  display: inline-flex !important;
  align-items: center !important;
}

.u-tag {
  display: inline-flex !important;
  align-items: center !important;
  margin: 2rpx !important;
}

/* 修复可能的显示问题 */
uni-view, uni-text, uni-button {
  box-sizing: border-box;
}

/* 确保图标正常显示 */
.uview-icon {
  font-family: 'uview-icon' !important;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style> 